<?php
/**
 * Created by PhpStorm.
 * User: xiemi
 * Date: 2020/3/31
 * Time: 20:55
 */

namespace darksun;

use darksun\handler\HandlerInterface;

class ExceptionHandle extends \Exception implements HandlerInterface
{
    private $app;

    public function bootService($app){
        $this->app = $app;
        set_exception_handler([$this, 'exceptionHandler']);
    }

    public function exceptionHandler($exception){
        $code = $exception->getCode();
        $message = $exception->getMessage();
        $file = $exception->getFile();
        $line = $exception->getLine();
        $msg = '[FILE]'.$file.'[LINE]'.$line.'[CODE]'.$code.'[MESSAGE]'.$message;
        $this->app->log->error($msg);
    }
}